<!DOCTYPE HTML>
<html>
	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
		<meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    	<title>统战成员学习平台</title>
	    <link rel="stylesheet" type="text/css" href="../../css/base.css" />
	    <link rel="stylesheet" type="text/css" href="../../css/style.css" />
	</head>
	<body class="white">
		<div id="app" style="display:none" v-show="true">
			<div class="lesson_comment_header ui_border_b">用户评论 ({{total}}条)<span @click="comment()" class="btn">我要评论</span></div>
			<transition-group name="list" tag="ul" class="lesson_comment_list">
				<li class="ui_border_b" v-for="item of items" :key="item">
					<img :src="imageBasePath + item.usrImg"  onerror="this.src=''">
					<div>
						<p class="name">{{item.usrName}}<span @click="vote(item)" class="zan float_r"><i :class="item.voteState ? 'icon_zaned' : 'icon_zan'"></i>{{item.voteCount}}</span></p>
						<p class="content">{{item.content}}</p>
						<p class="date">{{item.createDate}}</p>
					</div>
				</li>
				<li v-if="loaded" class="more" key="-1">已经到底了</li>
				<li v-else @click="getList()" class="more" :key="0">查看更多评论</li>
			</transition-group>
			<transition name="fade">
				<spinner v-if="loading"></spinner>
			</transition>
		</div>
		<script type="text/javascript" src="../../script/api.js"></script>
		<script type="text/javascript" src="../../script/vue.min.js"></script>
		<script type="text/javascript" src="../../script/common.js"></script>
		<script type="text/javascript" src="../../script/layer_mobile/layer.js"></script>
		<script type="text/javascript">
		    new Vue({
				el: '#app',
		     	data: {
					courseId: 0,
					total: 0,
					items: [],
					loading: false,
					loaded: false,
					pageNum: 1,
					pageSize: 10
		     	},
				mounted: function() {
		        	var $this = this;
		        	apiready = function() {
						$this.courseId = api.pageParam.courseId;
						$this.getList();
						api.addEventListener({
						    name: 'refresh_lesson_comment_event'
						}, function(ret, err){
							$this.pageNum = 1;
							$this.items = [];
							$this.loaded = false;
						    $this.getList();
						});
                	}
		    	},
		    	methods: {
					getList: function() {
						var $this = this;
						if($this.loading) return;
						$this.loading = true;
						post('/client/courseMsg/courseMsgList', {
							courseId: $this.courseId,
							pageNum: $this.pageNum,
							pageSize: $this.pageSize
						}, function(ret) {
							$this.loading = false;
							if(ret.isSuccess) {
								ret.data.list.forEach(function(item) {
									$this.items.push(item)
								});
								$this.total = ret.data.total;
								ret.data.isLastPage ? $this.loaded = true : $this.pageNum++;
								parseTapmode();
							} else {
								msgUtil.toast({
								    msg: ret.message
								});
							}
						});
					},
					vote: function(item) {
						var $this = this;
                        post('/client/courseMsg/vote', {
                            courseMsgId: item.courseMsgId,
                            voteAction: item.voteState ? 0 : 1
                        }, function(ret) {
                            if(ret.isSuccess) {
								item.voteCount += item.voteState ? -1 : 1;
                                item.voteState = !item.voteState
                            }
                        });
					},
					comment: function() {
						var $this = this;
						api.sendEvent({
						    name: 'comment_pause_video_evnet'
						});
						$api.setStorage(_.LSEESONCOMMENT, 'true');
						openWin('lesson_comment_frm', {
							courseId: $this.courseId
						});
					}
		    	}
		    });
		</script>
	</body>
</html>
